package cn.xiaohaoo.process;


import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据集整合
 */
public class DatasetsMove {

    //dataset3 重组到dataset4
    public static void dataset3ToDataset4() {
        File file=new File("./datasets/dataset3");
        Map<String,Object> map=new HashMap<>();
        Arrays.stream(file.listFiles()).forEach(v-> {
            String name = v.getName().split("\\.")[0];
            File file1 = new File("./datasets/dataset4/" + name + "/" + name + "_1.jpg");
            file1.getParentFile().mkdir();
            try {
                Files.copy(v.toPath(),file1.toPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

    }


    //dataset1重命名
    public static void dataset1Rename() {
        File file=new File("./datasets/dataset1");
        Arrays.stream(file.listFiles()).forEach(v-> {
            String s = v.getName().split("\\.")[0];
            File file1 = new File(file, s + ".jpg");
            v.renameTo(file1);
        });
    }


    //dataset1和2移动
    public static void dataset1And2ToDataset4() {
        File file = new File("./datasets/dataset4");
        Arrays.stream(file.listFiles()).forEach(v -> {
            String name = v.getName();
            File file1 = new File("./datasets/dataset1/"+name+".jpg");
            if (file1.exists()){
                try {
                    Files.copy(file1.toPath(),new File(v,name+"_2.jpg").toPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            File file2 = new File("./datasets/dataset2/"+name+".jpg");
            if (file2.exists()){
                try {
                    Files.copy(file2.toPath(),new File(v,name+"_3.jpg").toPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public static void main(String[] args) {
        dataset3ToDataset4();
        dataset1And2ToDataset4();
    }

}
